﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProgramCat.FiddlerExtension.Core.Utils;
using ProgramCat.FiddlerExtension.Core.Utils.Crypto;
using ProgramCat.FiddlerExtension.Core.Utils.UiEx;

namespace ProgramCat.FiddlerExtension.Core.TranscodingEditor
{
    public partial class TranscodingEditor : UserControl
    {
        public TranscodingEditor()
        {
            InitializeComponent();
            textBoxT.AddSelectionChanged((num)=> {
                label2.Text = num.ToString();
            });
            textBoxD.AddSelectionChanged((num) => {
                label2.Text = num.ToString();
            });
        }

        private void ContextMenuShow(ContextMenuStrip contextMenuStrip_, Control control)
        {
            contextMenuStrip_.Show(control, new Point(0, control.Height));
        }
        private void button_加密解密_Click(object sender, EventArgs e)
        {
            ContextMenuShow(contextMenuStrip_加密解密, button_加密解密);
        }
        private void button_编码转换1_Click(object sender, EventArgs e)
        {
            ContextMenuShow(contextMenuStrip_编码转换1, button_编码转换1);
        }
        private void button_编码转换2_Click(object sender, EventArgs e)
        {
            ContextMenuShow(contextMenuStrip_编码转换2, button_编码转换2);
        }
        private void button_取哈希值_Click(object sender, EventArgs e)
        {
            ContextMenuShow(contextMenuStrip_取哈希值, button_取哈希值);
        }
        private void button_一键解码_Click(object sender, EventArgs e)
        {
            ContextMenuShow(contextMenuStrip_一键解码, button_一键解码);
        }

        private void uRL加密GBKToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.UrlEncode(EncodedHelp.EncodingType.GBK);
        }
        private void uRL解密GBKToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.UrlDecode(EncodedHelp.EncodingType.GBK);
        }
        private void uRL加密UTF8ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.UrlEncode(EncodedHelp.EncodingType.UTF8);
        }
        private void uRL解密UTF8ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.UrlDecode(EncodedHelp.EncodingType.UTF8);
        }
        private void bASE64编码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.Base64Encode(EncodedHelp.EncodingType.GBK);
        }
        private void bASE64解码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.Base64Decode(EncodedHelp.EncodingType.GBK);
        }

        private void 简体繁体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.CHS2TW();
        }

        private void 繁体简体ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.TW2CHS();
        }

        private void 北京时间格林威治ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.ConvertDateTimeToString();

        }

        private void 格林威治北京时间ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.ConvertStringToDateTime();
        }

        private void ansiusc2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.Escape();
        }

        private void usc2ansiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.UnEscape();
        }

        private void gB2312UTF8ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.Gb2312ToUtf8();
        }

        private void uTF8GB2312ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.Utf8ToGb2312();

        }

        private void ansiUnicodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.Ansi2unicode();

        }

        private void unicodeansiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.unicode2Ansi();

        }

        private void unicodeUTF8ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.UnicodeToutf8();

        }

        private void uTF8UnicodeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.Utf8Tounicode();
        }

        private void 取MD4ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.GetMD4();
        }

        private void 取MD5ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.GetMD5();
        }

        private void 取sha1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.GetSHA1();
        }

        private void 取sha256ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.GetSHA256();
        }

        private void 取sha512ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.GetSHA512();
        }

        private void 取crc32ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBoxD.Text = textBoxT.Text.GetCRC();

        }

        private void 一键编码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string code = textBoxT.Text;
            textBoxD.Text = string.Format("URL编码(GBK)：\t{0}\r\n" +
                                      "URL编码(UTF8)：\t{1}\r\n" +
                                      "BASE64编码：\t{2}\r\n" +
                                      "ansi转usc2：\t{3}\r\n" +
                                      "Ansi转Unicode：\t{4}\r\n" +
                                      "GB2312转UTF8：\t{5}\r\n" +
                                      "--------------------------------------------------\r\n" +
                                      "取MD4值：\t{6}\r\n" +
                                      "取MD5值：\t{7}\r\n" +
                                      "取CRC值：\t{8}\r\n" +
                                      "取SHA1值：\t{9}\r\n" +
                                      "取sha256值：\t{10}\r\n" +
                                      "取sha512值：\t{11}",
                                      code.UrlEncode(EncodedHelp.EncodingType.GBK),
                                      code.UrlEncode(EncodedHelp.EncodingType.UTF8),
                                      code.Base64Encode(EncodedHelp.EncodingType.GBK),
                                      code.Escape(),
                                      code.Ansi2unicode(),
                                      code.Gb2312ToUtf8(),
                                      code.GetMD4(),
                                      code.GetMD5(),
                                      code.GetCRC(),
                                      code.GetSHA1(),
                                      code.GetSHA256(),
                                      code.GetSHA512()
                                      );
        }

        private void 一键解码ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string code = textBoxT.Text;
            textBoxD.Text = string.Format("URL解码(GBK)：\t{0}\r\n" +
                                      "URL解码(UTF8)：\t{1}\r\n" +
                                      "BASE64解码：\t{2}\r\n" +
                                      "usc2转ansi：\t{3}\r\n" +
                                      "Unicode转Ansi：\t{4}\r\n" +
                                      "Utf8转GB2312：\t{5}\r\n" +
                                      "--------------------------------------------------\r\n" +
                                      "取MD4值：\t{6}\r\n" +
                                      "取MD5值：\t{7}\r\n" +
                                      "取CRC值：\t{8}\r\n" +
                                      "取SHA1值：\t{9}\r\n" +
                                      "取sha256值：\t{10}\r\n" +
                                      "取sha512值：\t{11}",
                                      code.UrlDecode(EncodedHelp.EncodingType.GBK),
                                      code.UrlDecode(EncodedHelp.EncodingType.UTF8),
                                      code.Base64Decode(EncodedHelp.EncodingType.GBK),
                                      code.UnEscape(),
                                      code.unicode2Ansi(),
                                      code.Utf8ToGb2312(),
                                      code.GetMD4(),
                                      code.GetMD5(),
                                      code.GetCRC(),
                                      code.GetSHA1(),
                                      code.GetSHA256(),
                                      code.GetSHA512()
                                      );
        }

        private void button_交换_Click(object sender, EventArgs e)
        {
            string temp = textBoxT.Text;
            textBoxT.Text = textBoxD.Text;
            textBoxD.Text = temp;
        }
    }
}
